<?php
apf_require_class("Bll_BLL");
class Bll_Attendance_UserExt extends BLL{

    /**
    * 返回已使用年假
    * @param  int $user_id
    * @return int
    */
    public function get_used_annual($user_id){
        $row = $this->get_deault_dao()->find_row(array('user_id'=>$user_id));
        if(empty($row['annual_used'])){
            return 0;
        }
        return $row['annual_used'];
    }
    public function get_used_annual_by_ids($user_ids){
        $_where = array("user_id IN(".implode(',',$user_ids).") AND 1=?"=>1);
        return $this->get_deault_dao()->find_assoc($_where);
    }

    /**
    * 更新已使用年假
    * @param  int $user_id
    * @return int
    */
    public function update_used_annual($user_id,$days){
        $result = '';
        if(empty($user_id) || empty($days)) {
            return $result;
        }
        $row = $this->get_deault_dao()->find_by_id($user_id);
        if(empty($row['annual_used'])){
            $_data['user_id'] = $user_id;
            $_data['annual_used'] = $days;
            $result = $this->get_deault_dao()->insert($_data);
        } else {
            $_data['annual_used'] = $days + $row['annual_used'];
            $result = $this->get_deault_dao()->update_by_id($user_id,$_data);
        }
        return $result;
    }
    /**
     * 查询员工的请假状态，是否有产假和产前假
     * @param int $user_id
     * @return number|unknown
     * @deprecated
     */
    public function get_last_leave_status($user_id){
        $result = 0;
        if(empty($user_id)) {
            return $result;
        }
        $row = $this->get_deault_dao()->find_by_id($user_id);
        return $row['leave_status'];
    }
    public function update_leave_status($user_id,$status=0){
        return $this->get_deault_dao()->update(array('leave_status'=>$status),array('user_id'=>$user_id));
    }
    /**
     * @return new DAO_Attendance_UserExt
     */

    private function get_deault_dao(){
        return $this->get_dao('DAO_Attendance_UserExt');
    }
}